package com.wingscode.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.Query;
import com.wingscode.modules.sys.dao.DictionaryKeyDao;
import com.wingscode.modules.sys.entity.DictionaryKeyEntity;
import com.wingscode.modules.sys.service.DictionaryKeyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 字典key
 *
 * @author yan
 */
@Service("dictionaryKeyService")
public class DictionaryKeyServiceImpl extends ServiceImpl<DictionaryKeyDao, DictionaryKeyEntity> implements DictionaryKeyService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String type = "", name = "";
		if (params.containsKey("name"))
			name = (String)params.get("name");
		if (params.containsKey("type"))
			type = (String)params.get("type");

		IPage<DictionaryKeyEntity> page = this.page(
			new Query<DictionaryKeyEntity>().getPage(params),
			new QueryWrapper<DictionaryKeyEntity>()
				.like(StringUtils.isNotBlank(name),"name", name)
				.eq(StringUtils.isNotBlank(type), "type", type)
				.ne("type", "adType")
				.ne("type", "serviceType")
				.ne("type", "infoType")
				.orderByAsc("sort")
				.orderByDesc("id")
		);

		return new PageUtils(page);
	}
	
	@Override
	public List<DictionaryKeyEntity> getList() { return baseMapper.getList(); }

	@Override
	public void deleteBatch(Long[] Id) {
		this.removeByIds(Arrays.asList(Id));
	}
}
